<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/static/icon/favicon.ico" type="image/x-icon">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>数据库对比工具</title>
</head>
<body>
<script>
    let modelParam = {
        sqlId: "#sqlBody",
        modelId: "#model-edit",
        titleId: "#model-edit-title",
        resultId: "#model-result",
        dbId: "#db_id",
        formId: "#form-data",
        leftId: "leftId",
        rightId: "rightId"
    }
</script>

<div class="page-header">
    <h1 class="starter-template">数据库来源配置列表 <small>数据库比对的基本元素</small></h1>
</div>

<p>
    <button id="button-add" type="button" class="btn btn-primary" data-toggle="modal" onclick="add(this,modelParam)">新增</button>
</p>

<hr/>

<form class="form-inline">
    <div class="form-group">
        <label for="leftId">比对ID</label>
        <input type="text" class="form-control" id="leftId" placeholder="左库ID">
    </div>
    <div class="form-group">
        <label for="rightId">比对ID</label>
        <input type="email" class="form-control" id="rightId" placeholder="右库ID">
    </div>
    <button id="button-compare" type="button" class="btn btn-primary" data-toggle="modal" onclick="compare(modelParam)">比对</button>
</form>

<hr/>

<!--比对结果模态框-->
<div id="model-result" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">差异补齐SQL</h4>
            </div>
            <div class="modal-body">
                <p id="sqlBody"></p>
            </div>
            <div class="modal-footer">
<!--                <button type="button" class="btn btn-primary" onclick="copySql(modelParam)">一键拷贝SQL</button>-->
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--数据库配置模态框-->
<div id="model-edit" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 id="model-edit-title" class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body">
                <form id="form-data">
                    <div class="form-group">
                        <label for="db_id">ID</label>
                        <input type="text" class="form-control" id="db_id" placeholder="自动生成" disabled>
                    </div>
                    <div class="form-group">
                        <label for="db_name">备注名</label>
                        <input type="text" class="form-control" id="db_name">
                    </div>
                    <div class="form-group">
                        <label for="db_host">数据库地址</label>
                        <input type="text" class="form-control" id="db_host" placeholder="xx.xx.xx.xx或域名">
                    </div>
                    <div class="form-group">
                        <label for="db_port">端口号</label>
                        <input type="text" class="form-control" id="db_port">
                    </div>
                    <div class="form-group">
                        <label for="db_username">用户名</label>
                        <input type="text" class="form-control" id="db_username" placeholder="数据库用户名">
                    </div>
                    <div class="form-group">
                        <label for="db_password">密码</label>
                        <input type="password" class="form-control" id="db_password" placeholder="数据库密码">
                    </div>
                    <div class="form-group">
                        <label for="db_table_name">库名称</label>
                        <input type="text" class="form-control" id="db_table_name" placeholder="库名称">
                    </div>
                    <div class="form-group">
                        <label for="db_group_id">分组名称</label>
                        <select class="form-control" id="db_group_id">
                            <option value="">请选择分组</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="btn-save" class="btn btn-primary" data-loading-text="提交中..." onclick="sendData('form-data')">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<table class="table table-hover">
    <thead>
        <tr>
            <th>序号</th>
            <th>ID</th>
            <th>备注名</th>
            <th>数据库地址</th>
            <th>端口号</th>
            <th>用户名</th>
            <th>库名称</th>
            <th>分组名称</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody id="dataTable"></tbody>
</table>



<link rel="stylesheet" href="/static/css/list/list.css">
<!-- Bootstrap -->
<link rel="stylesheet" href="/static/bootstrap-dist/css/bootstrap.css" crossorigin="anonymous">

<script src="/static/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script src="/static/bootstrap-dist/js/bootstrap.min.js"></script>
<script src="/static/js/list.js"></script>

<script>
    function sendData(formId) {
        let inputList = document.getElementById(formId).querySelectorAll("input");
        let data = {
            id: inputList[0].value,
            name: inputList[1].value,
            host: inputList[2].value,
            port: inputList[3].value,
            userName: inputList[4].value,
            password: inputList[5].value,
            schemaName: inputList[6].value,
            sortId:$("#db_group_id").val()
        };

        let param = {
            url: "/detail/editDetail",
            data: data,
        }
        $.post(param.url, data, function (data) {
            alert(data.result);
            $("#btn-save").button("reset");
            $("#model-edit").modal("toggle");
            initTableList();
        });
    }
</script>
</body>
</html>